home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / vmath10.zip / VMATH10.PAS < prev    next >
Pascal/Delphi Source File  |  1991-05-21  |  19KB  |  535 lines

  1. {-------------------------------->  Vmath  <---------------------------------}
  2. { This unit contains vector and matrix procedures and functions for TURBO-   }
  3. { PASCAL, partly written as inline assembler code for a 387 coprocessor.     }
  4. { They are about two to three times faster than the equivalent "pure PASCAL" }
  5. { code.                                                                      }
  6. { Known features/limitations/bugs etc.:                                      }
  7. { - The unit has been written with TP6.0 on an 386SX/IIT387SX machine        }
  8. { - The procedure MulM4V4 needs an IIT coprocessor                           }
  9. { - The 287 coprocessor needs additional FWAIT commands in of strategic      }
  10. {   places all over the code, since I don't have one I didn't bother.        }
  11. { - All routines PUSH DS on entry, use long pointers (You don't want to      }
  12. {   be limited to 64K won't You ?) for operand access and POP DS on exit     }
  13. { - No testing of the routines has been carried out except that they work    }
  14. {   fine and fast in my application - NO WARRANTY !                          }
  15. { - I wrote the routines as I needed them (or as I wanted to find out how to }
  16. {   do it, in the case of MulM4V4) but at least the Vector3 operations are   }
  17. {   quite complete by now. If I find the time some more Matrix3 code may     }
  18. {   follow.                                                                  }
  19. {----------------------------------------------------------------------------}
  20. { These routines contain no special artifice, but are straightforward        }
  21. { coded "mathematical common knowledge", so everybody is free to copy        }
  22. { and modify the whole unit or parts of it. And remember: Distributing       }
  23. { sourcecode advances the "Art of Computing" by allowing others to learn     }
  24. { from Your mistakes !                                                       }
  25. {----------------------------------------------------------------------------}
  26. { I would be pleased to get some feedback (comments/additions/questions or   }
  27. { even a sample application using this unit) from users of Vmath -preferably }
  28. { via Email - Internet: mowl@cc.flinders.edu.au                              }
  29. {                                                                            }
  30. {     _--_|\                     Wolfgang Lieff                              }
  31. {    /      \  Flinders Institute for Atmospheric and Marine Sciences        }
  32. {    \_.--x_/          Bedford Park , South Australia 5042                   }
  33. {          v                                                                 }
  34. {----------------------------------------------------------------------------}
  35. { Version 1.0 of 20/05/1991 by Wolfgang Lieff                                }
  36. {----------------------------------------------------------------------------}
  37. unit Vmath10;
  38.  
  39. interface
  40.  
  41. type Matrix4  = array[0..3,0..3] of double;
  42.      Vector4  = array[0..3] of double;
  43.      Matrix3  = array[0..2,0..2] of double;
  44.      Vector3  = array[0..2] of double;
  45.  
  46. const
  47.   ZeroV3   : Vector3 = (0.0,0.0,0.0);
  48.   XunityV3 : Vector3 = (1.0,0.0,0.0);
  49.   YunityV3 : Vector3 = (0.0,1.0,0.0);
  50.   ZunityV3 : Vector3 = (0.0,0.0,1.0);
  51.  
  52. {----------------------------------------------------------------------------}
  53. procedure DirectionV3(P1,P2:Vector3; var R:Vector3);
  54. {         ===========                                                        }
  55. {         Function     Calculates the unity direction vector from P1 to P2   }
  56. {                                                                            }
  57. {         Result type  Vector3                                               }
  58. {----------------------------------------------------------------------------}
  59. procedure MulV3V3(V1,V2:Vector3; var R:Vector3);
  60. {         =======                                                            }
  61. {         Function     Multiplies the components of two vectors              }
  62. {                                                                            }
  63. {         Result type  Vector3                                               }
  64. {----------------------------------------------------------------------------}
  65. function  MulV3(V1,V2:Vector3):double;
  66. {         =====                                                              }
  67. {         Function     Scalar multiplication (dot product) of two vectors    }
  68. {                                                                            }
  69. {         Result type  double                                                }
  70. {----------------------------------------------------------------------------}
  71. procedure CrossV3(V1,V2:Vector3; var R:Vector3);
  72. {         =======                                                            }
  73. {         Function     Vector multiplication (cross product) of two vectors  }
  74. {                                                                            }
  75. {         Result type  Vector3                                               }
  76. {----------------------------------------------------------------------------}
  77. procedure NormalizeV3(var V:Vector3);
  78. {         ===========                                                        }
  79. {         Function     Transforms a vector into a unity vector with the same }
  80. {                      direction                                             }
  81. {                                                                            }
  82. {         Result type  Vector                                                }
  83. {----------------------------------------------------------------------------}
  84. function  AbsV3(V:Vector3):double;
  85. {         =====                                                              }
  86. {         Function     Returns the length of a vector                        }
  87. {                                                                            }
  88. {         Result type  double                                                }
  89. {----------------------------------------------------------------------------}
  90. function  QuickAbsV3(V:Vector3):double;
  91. {         ==========                                                         }
  92. {         Function     Returns a rough estimate of the length of a vector    }
  93. {                      by simply adding the absolute values of the components}
  94. {                                                                            }
  95. {         Result type  double                                                }
  96. {----------------------------------------------------------------------------}
  97. procedure MulV3D(V:Vector3; S:double; var R:Vector3);
  98. {         ======                                                             }
  99. {         Function     Multiplies the components of a vector with a scalar   }
  100. {                                                                            }
  101. {         Result type  Vector3                                               }
  102. {----------------------------------------------------------------------------}
  103. procedure DivV3D(V:Vector3; S:double; var R:Vector3);
  104. {         ======                                                             }
  105. {         Function     Divides the components of a vector by a scalar        }
  106. {                                                                            }
  107. {         Result type  double                                                }
  108. {----------------------------------------------------------------------------}
  109. procedure DivV3V3(V1,V2:Vector3; R:Vector3);
  110. {         =======                                                            }
  111. {         Function     Divides the components of two vectors                 }
  112. {                                                                            }
  113. {         Result type  double                                                }
  114. {----------------------------------------------------------------------------}
  115. procedure AddV3(V1,V2:Vector3; var R:Vector3);
  116. {         =====                                                              }
  117. {         Function     Adds two vectors                                      }
  118. {